﻿using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Globalization;

namespace _18.ExtractAllDatesFromText
{
    class ExtractAllDatesFromText
    {
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA");
            string text = "This is a sample text with dates like 12.01.2012 or other like 12.1.12 or 13.13.2013 or 12.12.2025";
            string pattern = @"\b\d{2}.\d{2}.\d{4}\b";
            Regex rgx = new Regex(pattern);
            Match m = rgx.Match(text);
            while (m.Success)
            {
                DateTime number=new DateTime();
                if (DateTime.TryParseExact(m.Value, "dd.MM.yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out number))
                {
                    Console.WriteLine("{0:d.MM.yyyy}",number);
                }
                m = m.NextMatch();
            }
        }
    }
}
